package com.etoak.common.core.vo;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVO<T> {

    /** 响应码 */
    private Integer code;
    /** 响应消息 */
    private String message;
    /** 响应结果 */
    private T data;
    /** 执行成功返回的状态码 */
    public static final int SUCCESS_CODE = 200;
    /** 执行成功返回的状态信息 */
    public static final String SUCCESS_MESSAGE = "success";

    public static final int FAILED_CODE = 500;
    /** 未捕获的异常 */
    public static final String FAILED_MESSAGE = "系统异常";

    //===============================================================
    public static final int HTTP_METHOD_NOT_SUPPORT_CODE = 405;

    public static final String HTTP_METHOD_NOT_SUPPORT_MESSAGE = "请求方法错误！";

    public static final int HTTP_MEDIA_TYPE_NOT_SUPPORT_CODE = 415;

    public static final String HTTP_MEDIA_TYPE_NOT_SUPPORT_MESSAGE = "请求参数类型错误！";
    //=================================================================

    public static <T> ResultVO<T> success() {
        return success(null);
    }

    public static <T> ResultVO<T> success(T data) {
        return new ResultVO<>(SUCCESS_CODE,SUCCESS_MESSAGE,data);
    }

    public static <T> ResultVO<T> failed() {
        return failed(FAILED_MESSAGE);
    }

    public static <T> ResultVO<T> failed(String message) {
        return failed(FAILED_CODE,message);
    }
    /**
     *自定义错误码和错误消息
     */
    public static <T> ResultVO<T> failed(int code,String message) {
        return new ResultVO<>(code,message,null);
    }
}
